package com.swlz.service.impl;

import java.sql.SQLException;

import com.swlz.dao.RoleMenuDAO;
import com.swlz.entity.RoleMenu;
import com.swlz.exception.CodeException;
import com.swlz.service.RoleMenuService;
import com.swlz.vo.PageVO;

/**
 * <pre>
 * 业务逻辑接口具体实现类
 * 系统角色菜单
 * ClassName : com.swlz.service.impl.RoleMenuServiceImpl
 * Author : swlz
 * E-Mail : 2233875735@qq.com
 * Date : 2020-06-24 11:03:29
 * Version : 1.0
 * Copyright 2020 swlz.top Inc. All rights reserved. 
 * Warning: this content is only for internal circulation of the company. It is forbidden to divulge it or use it for other commercial purposes
 * </pre>
 **/
public class RoleMenuServiceImpl implements RoleMenuService {
	
	private RoleMenuDAO roleMenuDAO = new RoleMenuDAO();

	@Override
	public int add(RoleMenu roleMenu) throws CodeException {
		try {
			return roleMenuDAO.insertSelective(roleMenu);
		} catch (SQLException e) {
			throw new CodeException(500, "添加系统角色菜单错误",e);
		}
	}

	@Override
	public int update(RoleMenu roleMenu) throws CodeException {
		try {
			return roleMenuDAO.updateSelective(roleMenu);
		} catch (SQLException e) {
			throw new CodeException(501, "修改系统角色菜单错误",e);
		}
	}

	@Override
	public int delete(Long roleMenuId) throws CodeException {
		try {
			return roleMenuDAO.deleteById(roleMenuId);
		} catch (SQLException e) {
			throw new CodeException(502, "删除系统角色菜单错误",e);
		}
	}

	@Override
	public RoleMenu get(Long roleMenuId) throws CodeException {
		try {
			return roleMenuDAO.selectById(roleMenuId);
		} catch (SQLException e) {
			throw new CodeException(503, "获取系统角色菜单失败",e);
		}
	}

	@Override
	public PageVO<RoleMenu> page(RoleMenu roleMenu, Integer current, Integer rowMax) throws CodeException {
		try {
			long total = roleMenuDAO.countByModel(roleMenu);
			PageVO<RoleMenu> page = new PageVO<>(total, current, rowMax);
			return page.setList(roleMenuDAO.selectByModel(roleMenu, page.getOffset(), page.getRowMax()));
		} catch (SQLException e) {
			throw new CodeException(504, "获取系统角色菜单分页数据失败",e);
		}
	}


}
